package com.xzx.study;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class SecondActivity extends AppCompatActivity implements View.OnClickListener{

    private EditText et_second_msg;
    private Button btn_second_back1;
    private Button btn_second_back2;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        Intent intent = getIntent();
        String msg = intent.getStringExtra("msg");
        et_second_msg = findViewById(R.id.et_second_msg);
        et_second_msg.setText(msg);
        btn_second_back1 = findViewById(R.id.btn_second_back1);
        btn_second_back2 = findViewById(R.id.btn_second_back2);

        btn_second_back1.setOnClickListener(this);
        btn_second_back2.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        if (v == btn_second_back1) {
            finish();
        } else if (v == btn_second_back2){
            int resultCode = 2;
            Intent intent = new Intent(); // 返回的Intent只需要携带数据信息即可
            intent.putExtra("result", et_second_msg.getText().toString());
            setResult(resultCode, intent);
            finish();
        }
    }
}
